<script setup lang='ts'>
import { SubmitBtn } from '@fl/components'

const emits = defineEmits(['submit'])

const visible = defineModel<boolean>('visible', { required: true })
const loading = defineModel<boolean>('loading', { required: true })

const form = ref()

const formValues = ref({
    auditResult: '',
})

const columns = [
    {
        label: '审核结果',
        options: [
            {
                label: '通过',
                value: 1,
            },
            {
                label: '驳回',
                value: 2,
            },
        ],
        prop: 'auditResult',
        valueType: 'radio',
    },
    {
        label: '审批意见',
        prop: 'remark',
        valueType: 'copy',
    },
]

const rules = {
    auditResult: [
        {
            message: '请选择审核结果',
            required: true,
        },
    ],
}

function cancel() {
    // 重置数据
    visible.value = false
}
function reset() {
    form.value.formInstance.resetFields()
}
async function submit() {
    const valid = await form.value.formInstance.validate()
    if (valid) {
        const val = {
            ...formValues.value,

        }
        emits('submit', val)
    }
}

defineExpose({
    cancel,
})
</script>

<template>
    <PlusDialog v-model="visible"
                title="审核订单"
                width="800"
                close-on-press-escape
                @cancel="cancel"
                @closed="reset"
    >
        <PlusForm ref="form"
                  v-model="formValues"
                  :columns="columns"
                  :label-width="150"
                  :rules="rules"
                  :has-footer="false"
        />

        <template #footer>
            <div class="mx-auto">
                <el-button @click="cancel">
                    取消
                </el-button>

                <SubmitBtn type="primary"
                           :loading="loading"
                           @click="submit"
                >
                    提交
                </SubmitBtn>
            </div>
        </template>
    </PlusDialog>
</template>
